<style class="cp-pen-styles">
/*
.fixed_headers {table-layout:fixed;}
.fixed_headers th{-o-text-overflow:ellipsis;text-overflow:ellipsis;overflow:hidden;white-space:nowrap;}
.fixed_headers thead tr {display: block;}
.fixed_headers tbody {display: block;overflow:auto;width:100%;}
*/
#permissions td.permission {padding-left:2px}
table.fixed_headers tbody {display:block;height:195px;overflow-y:scroll;}
table.fixed_headers thead, tbody tr {display:table;width:100%;table-layout:fixed;}
table.fixed_headers thead {width: calc( 100% - 1.2em )}
table.fixed_headers th:first-child, .fixed_headers td:first-child{width:150px;min-width:150px;max-width: 150px} 
table.fixed_headers th, .fixed_headers td {text-align: left;word-break:break-all;}
</style>
<div class="help">
    <p><?php echo __('Permissions let you control what users can do on your site. Each user role (defined on the :user-roles) has its own set of permissions. Permissions also allow trusted users to share the administrative burden of running a busy site.', array(':user-roles' => HTML::anchor(Route::get('admin/role')->uri(), __('user roles page')))); ?></p>
</div>

<?php echo Form::open(Route::get('admin/permission')->uri(), array('id' => 'permission-form ', 'class' => 'permission-form form')) ?>

<?php include Kohana::find_file('views', 'errors/partial'); ?>
<!--[if lte IE 9]>
<div class="old_ie_wrapper">
<!--<![endif]-->
<table id="permissions" class="table table-striped table-bordered table-highlight fixed_headers">
    <thead>
        <tr>
            <th><?php echo __('Permission') ?></th>
            <?php foreach ($roles as $i => $role): ?>
                <th class="row-checkbox"><?php echo trim(ucwords(Text::plain($role->name))); ?></th>
            <?php endforeach ?>
        </tr>
    </thead>

    <?php
    foreach ($perms as $row) {
        $role_perms[$row->rid][$row->permission] = TRUE;
    }
    ?>

    <tbody style="height:500px;overflow-y:auto;">

        <?php foreach ($permissions as $key => $access_names): ?>
            <tr class="permission-group">
                <td class="permission-key" width="30%" colspan="<?php echo $count + 1 ?>">
                    <?php echo ucwords(Text::plain($key)) ?>
                </td>
            </tr>

            <?php foreach ($access_names as $perm => $name): ?>
                <tr class="<?php echo Text::alternate("odd", "even") ?>">
                    <td class="permission">
                        <div class="permission-item" id="permission-<?php echo str_replace(' ', '-', $perm) ?>" >
                            <strong><?php echo ucwords($name['title']) ?></strong>
                            <div class="description">
                                <p class="muted"><?php echo Text::plain($name['description']) ?></p>
                                <?php if (!empty($name['restrict access'])): ?>
                                    <cite class="permission-warning text-warning hidden">
                                        <?php echo __('Warning! Give to trusted roles only; this permission has security implications.'); ?>
                                    </cite>
                                <?php endif; ?>
                            </div>
                        </div>

                    </td>
                    <?php foreach ($roles as $i => $role): ?>
                        <td class="role-checkbox">
                            <?php echo Form::checkbox("roles[$role->id][$key$perm$i][name]", Text::plain($perm), isset($role_perms[$role->id][$perm])); ?>		
                            <?php echo Form::hidden("roles[$role->id][$key$perm$i][module]", $key); ?>
                            <?php echo Form::hidden("roles[$role->id][$key$perm$i][id]", $role->id) ?>
                        </td>
                    <?php endforeach ?>
                </tr>
            <?php endforeach ?>
        <?php endforeach ?>
    </tbody>

</table>
<!--[if lte IE 9]>
</div>
<!--<![endif]-->
<?php echo Form::submit('permissions', __('Save'), array('class' => 'btn btn-success pull-right')) ?>
<?php echo Form::close() ?>